﻿import QtQuick 2.11

import "."
import "_Global"
import "_Global/Button"
import "_Global/Popup"

import "_Global/Global.js" as GlobalJS
import "GameJS.js" as GameJS

//结束游戏对话框(Esc)
Popup {
    id: root
    //x: 200; y: 180

    innerWidth: Global.gamePos.mapGameConfig.rectBack.width
    innerHeight: Global.gamePos.mapGameConfig.rectBack.height
    color: '#00000000'
    visible: false
    //focus: true
    animationType: "fade"
    easingType: Easing.Linear
    duration: 200
    radius: 5           //圆角


    Image {
        source: Global._FixResourcePath_R("Media/Images/Exit/Back.png")
        anchors.fill: parent
    }

    ImageButton2 {
        x: Global.gamePos.mapGameConfig.rectClose.x
        y: Global.gamePos.mapGameConfig.rectClose.y
        width: Global.gamePos.mapGameConfig.rectClose.width
        height: Global.gamePos.mapGameConfig.rectClose.height

        source: Global._FixResourcePath_R("Media/Images/Exit/Close.png")

        soundEffectClick: Global.resource.effects.effectButton
        bEffectOn: Global.config.bEffectOn

        onButtonClicked: {
            root.close();
        }
    }
    ImageButton2 {
        x: Global.gamePos.mapGameConfig.rectMusic.x
        y: Global.gamePos.mapGameConfig.rectMusic.y
        width: Global.gamePos.mapGameConfig.rectMusic.width
        height: Global.gamePos.mapGameConfig.rectMusic.height

        source: Global.config.bMusicOn ?
                    Global._FixResourcePath_R("Media/Images/Exit/MusicOn.png") :
                    Global._FixResourcePath_R("Media/Images/Exit/MusicOff.png")

        onButtonClicked: {
            Global.config.bMusicOn = !Global.config.bMusicOn;
            GameManager.sl_SetSound(Global.config.bMusicOn, Global.config.bEffectOn);
        }
    }

    ImageButton2 {
        x: Global.gamePos.mapGameConfig.rectEffect.x
        y: Global.gamePos.mapGameConfig.rectEffect.y
        width: Global.gamePos.mapGameConfig.rectEffect.width
        height: Global.gamePos.mapGameConfig.rectEffect.height

        source: Global.config.bEffectOn ?
                    Global._FixResourcePath_R("Media/Images/Exit/EffectOn.png") :
                    Global._FixResourcePath_R("Media/Images/Exit/EffectOff.png")

        onButtonClicked: {
            Global.config.bEffectOn = !Global.config.bEffectOn;
            GameManager.sl_SetSound(Global.config.bMusicOn, Global.config.bEffectOn);
        }
    }

    ImageButton2 {
        x: Global.gamePos.mapGameConfig.rectExit.x
        y: Global.gamePos.mapGameConfig.rectExit.y
        width: Global.gamePos.mapGameConfig.rectExit.width
        height: Global.gamePos.mapGameConfig.rectExit.height

        source: Global._FixResourcePath_R("Media/Images/Exit/ExitButton.png")

        onButtonClicked: {
            Qt.quit();
        }
    }

    ColorButton {
        x: Global.gamePos.mapGameConfig.rectSpeed.x
        y: Global.gamePos.mapGameConfig.rectSpeed.y
        width: Global.gamePos.mapGameConfig.rectSpeed.width
        height: Global.gamePos.mapGameConfig.rectSpeed.height
        visible: GameManager.platform == "debug" ? true : false

        Text {
            text: qsTr("快")
        }
        onButtonClicked: {
            GameManager.sl_SetSpeed(1);
            Global.config.nQuestionShowDelay = GameManager.gameConfig["QuestionShowDelay"];
            Global.config.nComQuestionChoiceDelay = GameManager.gameConfig["ComQuestionChoiceDelay"];
        }
    }
    ColorButton {
        x: Global.gamePos.mapGameConfig.rectSpeed.x + Global.dpW(100)
        y: Global.gamePos.mapGameConfig.rectSpeed.y
        width: Global.gamePos.mapGameConfig.rectSpeed.width
        height: Global.gamePos.mapGameConfig.rectSpeed.height
        visible: GameManager.platform == "debug" ? true : false

        Text {
            text: qsTr("中")
        }
        onButtonClicked: {
            GameManager.sl_SetSpeed(0);
            Global.config.nQuestionShowDelay = GameManager.gameConfig["QuestionShowDelay"];
            Global.config.nComQuestionChoiceDelay = GameManager.gameConfig["ComQuestionChoiceDelay"];
        }
    }
    ColorButton {
        x: Global.gamePos.mapGameConfig.rectSpeed.x + Global.dpW(200)
        y: Global.gamePos.mapGameConfig.rectSpeed.y
        width: Global.gamePos.mapGameConfig.rectSpeed.width
        height: Global.gamePos.mapGameConfig.rectSpeed.height
        visible: GameManager.platform == "debug" ? true : false

        Text {
            text: qsTr("慢")
        }
        onButtonClicked: {
            GameManager.sl_SetSpeed(2);
            Global.config.nQuestionShowDelay = GameManager.gameConfig["QuestionShowDelay"];
            Global.config.nComQuestionChoiceDelay = GameManager.gameConfig["ComQuestionChoiceDelay"];
        }
    }

    /*
    Keys.onEscapePressed:  {
        event.accepted = true;
        root.hide();
        //root.focus = false;
    }*/
}
